<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="java.util.ArrayList"%>
<%@page import="com.group.weekmgr.CodeBean"%>
<%
// 	if(session.getAttribute("idKey")==null){
// 		response.sendRedirect("/login/login.html");
// 	}
	String week_code=request.getParameter("week_code");
	System.out.println("week_code:" + week_code);
%>
<jsp:useBean id="codeMgr" class="com.group.weekmgr.CodeMgr"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>Insert title here</title>
	<link rel="stylesheet" type="text/css" href="../etc/style.css">
	<script type="text/javascript">
		function addCode(){
			var code_chk = document.getElementsByName("code_chk");
			var no = document.getElementsByName("no");
			
			var param_no ="";
			
			for(var i=0; i<code_chk.length; i++){
				if(code_chk[i].checked==true){
					param_no += no[i].value+",";
				}
			}
// 			alert("param_no:" + param_no);
<%-- 			alert("week:" + <%=week_code%>); --%>
			if(<%=week_code%>==0){
				opener.location.href="performance_input.jsp?no="+param_no;
			}else if(<%=week_code%>==1){
				opener.location.href="plan_input.jsp?no="+param_no;
			}
			window.close();
		}
		
		function search(){
			if(search_frm.code_search_input.value===""){
				alert("검색어를 입력하세요.");
				search_frm.code_search_input.focus();
				return;
			}
			search_frm.submit();
		}
	</script>
</head>
<body>
	<h2>My 코드 추가</h2>
	<form action="mycode_add.jsp" method="post" name="search_frm">
		<table>
			<tr>
				<td>검색: 상세검색</td>
				<td>
					<select name="stype">
						<option value="code" selected="selected">코드</option>
						<option value="customer_name">고객사</option>
					</select>
				</td>
				<td>
					<input type="text" name="code_search_input">
					<input type="hidden" name="week_code" value="<%=week_code%>"/>
					<input type="submit" value="검색" onclick="search()">
				</td>
			</tr>
		</table>
	</form>
	<form name="datafrm" action="">
		<table border="1" width="60%">
			<tr>
				<th> - </th>
				<th>No</th>
				<th>코드</th>
				<th>고객사</th>
			</tr>
			<%
				request.setCharacterEncoding("UTF-8");
				
				String type = request.getParameter("stype");
				String word = request.getParameter("code_search_input");
				
				ArrayList<CodeBean> list = codeMgr.getCodeList(type, word);  
				for(int i=0; i<list.size(); i++){
					CodeBean bean = list.get(i);
			%>
			<tr align="center">
				<td><input type="checkbox" name="code_chk"></td>
				<td><input type="text"  size="1" name="no" readonly="readonly"  value="<%=bean.getCodeno() %>"></td>
				<td><input type="text"  name="code" readonly="readonly" value="<%=bean.getCode() %>"></td>
				<td>
					<input type="text"  name="customer_name" readonly="readonly" value="<%=bean.getCustomerName() %>">
					
				</td>
				
			</tr>
			<%
				}
			%>
		</table>
	</form>
	<br>
	<table align="right">
		<tr>
			<td>
				<input type="button" value="확인" onclick="addCode()">
			</td>
		</tr>
	</table>
</body>
</html>